package com.tom.imooc.dynamicdatasource;

import com.tom.ExampleApplication;
import com.tom.imooc.staticdatasource.DataSourceContext;
import lombok.Setter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @author zx
 * @date 2024年12月16日 20:19
 */
@SpringBootTest(classes = ExampleApplication.class)
public class TestDemo {
    @Setter(onMethod_ = @Autowired)
    private JdbcTemplate jdbcTemplate;

    @Test
    public void testQueryUser() {
        DataSourceContext.setCurrentDb("test_user");
        List list = jdbcTemplate.queryForList("select * from user");
        System.out.println("list: " + list);
    }

    @Test
    public void testQueryOrder() {
        DataSourceContext.setCurrentDb("test_order");
        List list = jdbcTemplate.queryForList("select * from `order`");
        System.out.println("list: " + list);
    }
}
